from calc_manager.plugins_inner.bdf_reader_inner import BDFReader
from calc_manager.plugins_inner.op2_reader_inner import OP2Reader
from pydantic import BaseModel
from typing import List, Dict


class Parameter(BaseModel):
    pass

class Result(BaseModel):
    rough_eids: List[float]
    refine_eids: List[float]

#def check_eid_old(eids):
#    refine_reference_eids = [
#        list(range(10000001, 15000000)),
#        list(range(15000001, 20000000)),
#        list(range(20000001, 29999999)),
#        list(range(30000001, 36999999)),
#        list(range(37000001, 39999999)),
#        list(range(40000001, 44999999)),
#        list(range(50000001, 54999999)),
#        list(range(60000001, 64999999)),
#        list(range(70000001, 79999999)),
#        list(range(80000001, 89999999)),
#        list(range(90000001, 94999999)),
#        list(range(91000001, 91499999)),
#        list(range(91500001, 91999999)),
#        list(range(92000001, 92999999)),
#        list(range(93000001, 93699999)),
#        list(range(93700001, 93999999)),
#        list(range(94000001, 94499999)),
#        list(range(95000001, 95499999)),
#        list(range(96000001, 96499999)),
#        list(range(97000001, 97999999)),
#        list(range(98000001, 98999999)),
#        list(range(99000001, 99499999)),
#    ]
#    set_refine_eids = set([item for subset in refine_reference_eids for item in subset])
#    # is_feine: 1代表精细网格，0代表自然网格
#    # result = {
#    #     "eid": [],
#    #     "is_refine":[]
#    # }
#    # for eid in eids:
#    #     result["eid"].append(eid)
#    #     if eid in set_refine_eids:
#    #         result["is_refine"].append(1)
#    #     else:
#    #         result["is_refine"].append(0)
#    rough_eids = [item for item in eids if item not in set_refine_eids]
#    refine_eids = [item for item in eids if item in set_refine_eids]
#    # 前者代表自然网格id,后者代表精细网格id
#    return rough_eids, refine_eids

def check_eid(eids):
    refine_reference_ranges = [
        (10000001, 14999999),
        (15000001, 19999999),
        (20000001, 29999999),
        (30000001, 36999999),
        (37000001, 39999999),
        (40000001, 44999999),
        (50000001, 54999999),
        (60000001, 64999999),
        (70000001, 79999999),
        (80000001, 89999999),
        (90000001, 94999999),
        (91000001, 91499999),
        (91500001, 91999999),
        (92000001, 92999999),
        (93000001, 93699999),
        (93700001, 93999999),
        (94000001, 94499999),
        (95000001, 95499999),
        (96000001, 96499999),
        (97000001, 97999999),
        (98000001, 98999999),
        (99000001, 99499999),
    ]

    def is_refine_eid(eid):
        for start, end in refine_reference_ranges:
            if start <= eid <= end:
                return True
        return False

    rough_eids = []
    refine_eids = []

    for eid in eids:
        if is_refine_eid(eid):
            refine_eids.append(eid)
        else:
            rough_eids.append(eid)

    return rough_eids, refine_eids


def first(param: Parameter, bdf_reader: BDFReader) :
    print("step1-----------------> start")
    eids = bdf_reader.get_element_ids()
    rough_eids, refine_eids = check_eid(eids)

    res =  Result(rough_eids=rough_eids, refine_eids=refine_eids)
    print("step1-----------------> end")
    return res
